home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10212 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: web.cae.ca!usenet
  2. From: fraserh@cae.ca (Fraser Hutchinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Simple question about constructors
  5. Date: 6 Mar 1996 18:11:41 GMT
  6. Organization: CAE Electronics Ltd.
  7. Message-ID: <4hkkgt$bpi@web.cae.ca>
  8. References: <4ha7d2$quc@cloner4.netcom.com> <4hbadp$t0p@cloner4.netcom.com>
  9. NNTP-Posting-Host: pch63.cae.ca
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <4hbadp$t0p@cloner4.netcom.com>, stefmit@ix.netcom.com says...
  15. >
  16. >It seems that the "copy constructor" day is one of my worst in the C++ 
  17. >learning process. Now I ran into another problem:
  18.  
  19. [description of class purpose deleted]
  20.  
  21. I have a linked list based on a template <class My_type>, which has a node 
  22. >class with (obviously) a pointer (let's call it *next) and an element field of 
  23. >the type My_type (called data). Then, I have a list class using the node 
  24. >above, with its own pointer *head (I am trying to build a sort of stack). I 
  25. >was able to build the stack (this was pretty easy), but then I tried to define 
  26. >a copy constructor in the list, using something similar to:
  27. >template <class My_type>
  28. >List<My_type> :: List(const List &newList)
  29. >{ head -> data = newList.head -> data;
  30.    ^^^^^^^^^^^^
  31. >  head -> next = newList.head -> next; }
  32.    ^^^^^^^^^^^^ 
  33.  
  34. OK, silly question, but has memory been allocated for this::head?  That this
  35. is a constructor implies to me that there hasn't, which means that you are 
  36. writing to a random memory location.
  37.  
  38. Fraser
  39.  
  40.  
  41.